package com.peace.hospital.opdept.service.outpatientdept.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peace.hospital.entity.common.Druginformation;
import com.peace.hospital.entity.outpatientdept.Drugcharges;
import com.peace.hospital.opdept.mapper.common.DruginformationMapper;
import com.peace.hospital.opdept.mapper.outpatientdept.DrugchargesMapper;
import com.peace.hospital.opdept.service.outpatientdept.IDrugchargesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 药品处方表 服务实现类
 * </p>
 *
 * @author 谢晓峰
 * @since 2019-11-25
 */
@Service
public class DrugchargesServiceImpl extends ServiceImpl<DrugchargesMapper, Drugcharges> implements IDrugchargesService {
    /**药品处方表*/
@Autowired
private DrugchargesMapper drugchargesMapper;
/**药品表*/
@Autowired
private DruginformationMapper druginformationMapper;
//获取药品收费信息
    @Override
    public List<Druginformation> selectDrugchargesByPid(Integer pid) {
        List<Druginformation> list = new ArrayList<>();
        List<Drugcharges> drugcharges = drugchargesMapper.selectDrugchargesByPid(pid);
        System.out.println(drugcharges);
        int falg =0;
        for (Drugcharges drugcharge : drugcharges) {
            drugcharge.getDrnum();//获取药品数量
            Integer drugid = drugcharge.getDrugid();//获取药品id
            Druginformation druginformation =  druginformationMapper.selectDrugchargesById(drugid);//查询获取药品单价
            druginformation.setDrugnum(drugcharge.getDrnum());
            list.add(falg,druginformation);
           falg++;
        }
        return list;
    }

    @Override
    public Double selectDrugpricesByPid(Integer pid) {
        //根据病人id查询药品处方收费
        Double falg = 0.0;
        List<Drugcharges> drugcharges = drugchargesMapper.selectDrugchargesByPid(pid);
        for (Drugcharges drugcharge : drugcharges) {
            drugcharge.getDrnum();//获取药品数量
            Integer drugid = drugcharge.getDrugid();//获取药品id
            Double doub =  druginformationMapper.selectPriceById(drugid);//查询获取药品单价
            falg+=doub;
        }
        return falg;
    }
}
